package com.example.extendanimationdemo;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.view.animation.Animation;
import android.view.animation.Transformation;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

public class ExpandAnimation extends Animation {
	private View view;
	private RelativeLayout.LayoutParams layoutParams;
	private int measuredHeight;

	public ExpandAnimation(View view) {
		super();
		this.view = view;
		this.view.measure(0, 0);
		measuredHeight = this.view.getMeasuredHeight();
		System.out.println("measuredHeight:" + measuredHeight);
		layoutParams = (android.widget.RelativeLayout.LayoutParams) view.getLayoutParams();
		// layoutParams.bottomMargin = measuredHeight;
	}

	public ExpandAnimation(Context context, AttributeSet attrs) {
		super(context, attrs);
		// TODO Auto-generated constructor stub
	}

	@Override
	protected void applyTransformation(float interpolatedTime, Transformation t) {
		// TODO Auto-generated method stub
		super.applyTransformation(interpolatedTime, t);
		// 0 1
		// measureHeight 2*measureHeight
		// layoutParams.bottomMargin = (int) (measuredHeight + (measuredHeight * interpolatedTime));
		layoutParams.setMargins(0, 0, 0, (int) (measuredHeight + (measuredHeight * interpolatedTime)));
		this.view.setAlpha(interpolatedTime);
		this.view.setLayoutParams(layoutParams);
		// this.view.requestLayout();
		System.out.println("layoutParams.bottomMargin:" + layoutParams.bottomMargin);
	}
}
